<?php
/**
 * setting controller
 * @package app-member_controller
 */
load_controller('/loggeduser');
/**
 * setting controller
 *
 * @author pandajingjing
 * @package app-member_controller
 */
class settingcontroller extends loggedusercontroller{

	function doRequest(){
		$arrErrInfo=array();
		$strAction=$this->getParam('action','url');
		load_lib('/bll/member/info');
		$clsBll=new bll_member_info();
		$arrUserInfo=$this->getUserInfo();
		switch($strAction){
			case 'pwd':
				$this->setData('bolShowPwd',true);
				$this->setData('bolShowBase',false);
				$strSubAction=$this->getParam('hidAction','post');
				if('savepwd'==$strSubAction){
					$strOldPwd=$this->getParam('pwdOldPwd','post');
					$strNewPwd=$this->getParam('pwdNewPwd','post');
					$strNewPwdCfm=$this->getParam('pwdNewPwdCfm','post');
					$intUserID=$this->getParam('hidUserID','post','int');
					$mixResult=$clsBll->updUserPwd($intUserID,$strOldPwd, $strNewPwd, $strNewPwdCfm);
					if(is_array($mixResult)){
						$arrErrInfo=$mixResult;
					}else{
						load_controller('/panel');
						$this->redirectURL(panelcontroller::getURL());
					}
				}else{
					$this->setViewState('frmEditPwd','hidAction','savepwd');
					$this->setViewState('frmEditPwd','hidUserID',$arrUserInfo['USERID']);
				}
				break;
			case 'base':
			default:
				$this->setData('bolShowBase',true);
				$this->setData('bolShowPwd',false);
				$strSubAction=$this->getParam('hidAction','post');
				if('savebase'==$strSubAction){
					$strNickName=$this->getParam('txtNickName','post');
					$strEmail=$this->getParam('txtEmail','post');
					$intUserID=$this->getParam('hidUserID','post','int');
					$intGender=$this->getParam('radGender','post','int');
					$mixResult=$clsBll->updUserBaseDetail($intUserID,$strNickName, $strEmail, $intGender,$this->getTime());
					if(is_array($mixResult)){
						$arrErrInfo=$mixResult;
					}else{
						load_controller('/panel');
						$this->redirectURL(panelcontroller::getURL());
					}
				}else{
					$arrBaseDetail=$clsBll->getUserBaseDetail($arrUserInfo['USERID']);
					$this->setViewState('frmEditInfo','txtNickName',$arrBaseDetail['NICKNAME']);
					$this->setViewState('frmEditInfo','txtEmail',$arrBaseDetail['EMAIL']);
					$this->setViewState('frmEditInfo','radGender',$arrBaseDetail['GENDER']);
					$this->setViewState('frmEditInfo','hidAction','savebase');
					$this->setViewState('frmEditInfo','hidUserID',$arrUserInfo['USERID']);
				}
				break;
		}
		
		load_controller('/logout');
		$this->setData('strLogoutURL',logoutcontroller::getURL());
		
		$strModPwdURL=self::getURL('pwd');
		$strModBaseURL=self::getURL('base');
		
		$this->setData('strModPwdURL',$strModPwdURL);
		$this->setData('strModBaseURL',$strModBaseURL);
		$this->setData('arrErrInfo',$arrErrInfo);
		return '/setting';
	}

	/**
	 * 获取访问该控制器的路径
	 */
	static function getURL($p_strAction='',$p_arrParam=array(),$p_bolSecure=false,$p_strPre='/setting'){
		return parent::getURL('/setting',$p_strAction,$p_arrParam);
	}
}